<?php
/*标准化函数*/
function standardization(&$a, $num)
{
	$maxN = max($a);
	$minN = min($a);
	for ($i = 0; $i < $num; $i++)
		$a[$i] = ($a[$i] - $minN) / ($maxN - $minN);
}
/*筛选不感兴趣函数*/
function dislike($DReason, $dnum, $EP, $NEP, &$LEP, &$Lnum)
{
	$DHighP = 99999; //能接受的最高价格
	$DLowP = 0; //能接受的最低价格
	$DWindows = 1; //是否喜欢Windows系统
	$DMacOS = 1; //是否喜欢MacOS系统
	$DScreen = array(); //不喜欢的屏幕大小
	$DScreen_num = 0;
	$DMemory = array(); //不喜欢的内存大小
	$DMemory_num = 0;
	$DCPU = array(); //不喜欢的CPU类型
	$DCPU_num = 0;
	for ($j = 0; $j < $dnum; $j++) {
		if ((!is_null($DReason[$j]['HighP'])) && ($DReason[$j]['HighP'] < $DHighP))
			$DHighP = $DReason[$j]['HighP'];
		else if (!is_null($DReason[$j]['Sys'])) {
			if (strstr($DReason[$j]['Sys'], "Windows"))
				$DWindows = 0;
			if (strstr($DReason[$j]['Sys'], "MacOS"))
				$DMacOS = 0;
		} else if (!is_null($DReason[$j]['Screen'])) {
			$DScreen[$DScreen_num] = $DReason[$j]['Screen'];
			$DScreen_num++;
		} else if (!is_null($DReason[$j]['Memory'])) {
			$DMemory[$DMemory_num] = $DReason[$j]['Memory'];
			$DMemory_num++;
		} else if (!is_null($DReason[$j]['CPU'])) {
			$DCPU[$DCPU_num] = $DReason[$j]['CPU'];
			$DCPU_num++;
		}
	}
	for ($i = 0; $i < $NEP; $i++) {
		//不感兴趣的价格
		if ($EP[$i]['EP_price'] >= $DHighP || $EP[$i]['EP_price'] <= $DLowP)
			continue;
		//不感兴趣的系统
		if (!$DWindows && strstr($EP[$i]['System'], 'Windows'))
			continue;
		else if (!$DMacOS && strstr($EP[$i]['System'], 'MacOS'))
			continue;
		//不感兴趣的屏幕大小
		for ($j = 0; $j < $DScreen_num; $j++) {
			$DScreen_f = 0;
			if (strcmp($EP[$i]['Screen_size'], $DScreen[$j]) == 0) {
				$DScreen_f = 1;
				break;
			}
		}
		if ($DScreen_f == 1)
			continue;
		//不感兴趣的内存大小
		for ($j = 0; $j < $DMemory_num; $j++) {
			$DMemory_f = 0;
			if (strcmp($EP[$i]['Memery_capa'], $DMemory[$j]) == 0) {
				$DMemory_f = 1;
				break;
			}
		}
		if ($DMemory_f == 1)
			continue;
		//不感兴趣的CPU
		for ($j = 0; $j < $DCPU_num; $j++) {
			$DCPU_f = 0;
			if (strstr($DCPU[$j], 'i3') && strstr($EP[$i]['CPU_version'], 'i3')) {
				$DCPU_f = 1;
				break;
			} else if (strstr($DCPU[$j], 'i5') && strstr($EP[$i]['CPU_version'], 'i5')) {
				$DCPU_f = 1;
				break;
			} else if (strstr($DCPU[$j], 'i7') && strstr($EP[$i]['CPU_version'], 'i7')) {
				$DCPU_f = 1;
				break;
			} else if (strstr($DCPU[$j], 'i9') && strstr($EP[$i]['CPU_version'], 'i9')) {
				$DCPU_f = 1;
				break;
			} else if (strstr($DCPU[$j], 'R5') && strstr($EP[$i]['CPU_version'], 'R5')) {
				$DCPU_f = 1;
				break;
			} else if (strstr($DCPU[$j], 'R7') && strstr($EP[$i]['CPU_version'], 'R7')) {
				$DCPU_f = 1;
				break;
			} else {
				if (strstr($EP[$i]['CPU_version'], $DCPU[$j])) { //Apple E1、J4125···
					$DCPU_f = 1;
					break;
				}
			}
		}
		if ($DCPU_f == 1)
			continue;
		$LEP[$Lnum] = $EP[$i]; //放入感兴趣的电脑数组中
		$Lnum++;
	}
}
/*按需筛选*/
function SelectByRequest($EPInfo, $i, $Request, $Rnum, &$EP, &$NEP)
{
	$flag2 = 0; //标记所有的需求是否满足
	for ($j = 0; $j < $i; $j++) {
		$Stype = $Request[0]['Stype'];
		for ($k = 0; $k < $Rnum; $k++) {
			$flag = 1; //标记每一个软件的需求是否满足
			if (strcmp($Request[$k]['Stype'], $Stype) != 0) {
				$Stype = $Request[$k]['Stype'];
				/*判断CPU_type是否满足要求*/
				if (!strstr($EPInfo['CPU_type'], $Request[$k]['CPU_type']) && $Request[$k]['CPU_type'] != "") {
					$flag = 0;
					break;
				}
				/*判断CPU_basefre是否满足要求*/
				if (strcmp($EPInfo[$j]['CPU_basefre'], $Request[$k]['CPU_basefre']) == -1) {
					$flag = 0;
					break;
				}
				/*判断Corenum是否满足要求*/
				if (strcmp($EPInfo[$j]['Corenum'], $Request[$k]['Corenum2']) == -1) {
					$flag = 0;
					break;
				}
				/*判断Card_type是否满足要求*/
				if (strcmp($EPInfo[$j]['Card_type'], $Request[$k]['Card_type']) != 0 && $Request[$k]['Card_type'] != "") {
					$flag = 0;
					break;
				}
				/*判断screen_dpi是否满足要求*/
				if (strcmp($EPInfo[$j]['Screen_dpi'], "其他") != 0 && $EPInfo[$j]['Screen_dpi'] != "") {
					$screen_dpi1 = explode("*", $EPInfo[$j]['Screen_dpi']);
					if ($Request[$k]['Screen_dpi'] != "") {
						$screen_dpi2 = explode("*", $Request[$k]['Screen_dpi']);
						if (strcmp($screen_dpi1[0], $screen_dpi2[0]) == -1 || strcmp($screen_dpi1[1], $screen_dpi2[1]) == -1) {
							$flag = 0;
							break;
						}
					}
				}
				/*判断SSD是否满足要求*/
				if ($Request[$k]['SSD2'] != "") {
					if (strstr($EPInfo[$j]['SSD'], "TB")) {
						$SSD1 = explode("TB", $EPInfo[$j]['SSD']);
						$SSD1[0] = $SSD1[0] * 1000;
					} else if (strstr($EPInfo[$j]['SSD'], "GB")) {
						$SSD1 = explode("GB", $EPInfo[$j]['SSD']);
					}
					$SSD2 = explode("GB", $Request[$k]['SSD2']);
					if (strcmp($SSD1[0], $SSD2[0]) == -1) {
						$flag = 0;
						break;
					}
				}
				/*判断Memory_capa是否满足要求*/
				if ($Request[$k]['Memory_capa'] != "") {
					$Memory_capa = explode("GB", $Request[$k]['Memory_capa']);
					if (strcmp($EPInfo[$j]['Memory_capa'], $Memory_capa[0]) == -1) {
						$flag = 0;
						break;
					}
				}
			}
			if ($flag == 0)
				break;
			else
				$flag2 = 1;
		}
		if ($flag2 == 1) {
			$EP[$NEP] = $EPInfo[$j];
			$NEP++;
		}
	}
}
/*流行度推荐*/
function PopularRanking(&$LEP, $Lnum)
{
	$sales = array();
	for ($j = 0; $j < $Lnum; $j++)
		$sales[$j] = $LEP[$j]['EP_sales'];
	standardization($sales, $Lnum);
	/*按评分从大到小排序*/
	for ($j = 0; $j < $Lnum; $j++)
		$LEP[$j]['EP_sales'] = $sales[$j];
	for ($j = 0; $j < $Lnum; $j++)
		$LEP[$j]['EP_score'] = 0.5 * (float)$LEP[$j]['EP_sales'] + 0.5 * (float)$LEP[$j]['EP_comnum'];
	for ($i = 0; $i < $Lnum; $i++) {
		for ($j = 0; $j < $Lnum - 1; $j++) {
			if ($LEP[$j]['EP_score'] < $LEP[$j + 1]['EP_score']) {
				$tmp = $LEP[$j + 1];
				$LEP[$j + 1] = $LEP[$j];
				$LEP[$j] = $tmp;
			}
		}
	}
}

/*数据库连接*/
$mysql_server_name = '49.233.16.5';
$mysql_username = 'echoose2';
$mysql_password = 'Echoose123456!';
$mysql_database = 'echoose_new';
$conn = mysqli_connect($mysql_server_name, $mysql_username, $mysql_password, $mysql_database); //连接数据库
//连接数据库错误提示
if (mysqli_connect_errno($conn)) {
	die("连接 MySQL 失败: " . mysqli_connect_error());
}
//echo "连接成功";
mysqli_query($conn, "set names utf8"); //数据库编码格式
mysqli_set_charset($conn, "utf8"); //设置默认客户端字符集。
// mysqli_select_db($conn,$mysql_database); //更改连接的默认数据库
//查询代码

$Major_name = $_GET['Mjr_name']; //从小程序处获取专业
$User_name = $_GET['User_name']; //从小程序处获取用户名
$page = $_GET['page']; //从小程序处获取页数
$TypeList = json_decode($_GET['TypeList'], true); //从小程序处获取笔记本类型列表
$UseList = json_decode($_GET['UseList'], true); //从小程序处获取用途列表
$BrandList = json_decode($_GET['BrandList'], true); //从小程序处获取品牌列表
$SSDList = json_decode($_GET['SSDList'], true); //从小程序处获取硬盘容量列表
$MemoryList = json_decode($_GET['MemoryList'], true); //从小程序处获取内存容量列表
$CPUList = json_decode($_GET['CPUList'], true); //从小程序处获取处理器列表
$ScreenList = json_decode($_GET['ScreenList'], true); //从小程序处获取屏幕尺寸列表
$CardList = json_decode($_GET['CardList'], true); //从小程序处获取显卡列表
$TypeChoose = json_decode($_GET['TypeChoose'], true);
$UseChoose = json_decode($_GET['UseChoose'], true);
$BrandChoose = json_decode($_GET['BrandChoose'], true);
$SSDChoose = json_decode($_GET['SSDChoose'], true);
$MemoryChoose = json_decode($_GET['MemoryChoose'], true);
$CPUChoose = json_decode($_GET['CPUChoose'], true);
$ScreenChoose = json_decode($_GET['ScreenChoose'], true);
$CardLChoose = json_decode($_GET['CardChoose'], true);
$HighPrice = $_GET['HighPrice']; //从小程序处获取区间上限
$LowPrice = $_GET['LowPrice']; //从小程序处获取区间下限

// $TypeList = array();
// $UseList = array();
// $BrandList = array();
// $SSDList = array();
// $MemoryList = array();
// $CPUList = array();
// $ScreenList = array();
// $CardList = array();
// $TypeChoose = array();
// $UseChoose = array();
// $BrandChoose = array();
// $SSDChoose = array();
// $MemoryChoose = array();
// $CPUChoose = array();
// $ScreenChoose = array();
// $CardChoose = array();
// $HighPrice = "4000";
// $LowPrice = "1000";
// $TypeList = ['游戏本', '轻薄本'];
// $UseList = ['日常办公', '平面设计', '室内/外设计', '机械设计', '建筑设计', '网页设计', '影视动画', '电子绘图', '编程开发', '理科学习', '数据分析'];
// $BrandList = ['联想', '戴尔', '惠普', 'Apple', '华为', '华硕', '小米', '微软'];
// $MemoryList = ['8G', '12G', '16G', '32G', '64G'];
// $SSDList = ['128G', '256G', '512G', '1T'];
// $CPUList = ['i5', 'i7', 'AMD R5', 'AMD R7'];
// $ScreenList = ['13.0英寸以下', '13.0-13.9英寸', '14.0-14.9英寸', '15.0-15.9英寸', '16.0英寸以上'];
// $CardList = ['独立显卡', '集成显卡'];
// $TypeChoose = [false, false];
// $UseChoose = [false, false, false, false, false, false, false, false, false, false, false];
// $BrandChoose = [false, true, false, false, false, false, false, false];
// $MemoryChoose = [false, false, false, false, false];
// $SSDChoose = [false, false, false, false];
// $CPUChoose = [false, false, false, false];
// $ScreenChoose = [false, false, false, false, false];
// $CardChoose = [false, false];
// $IsChosen = [false, false, false, false, false, false, false, false];

/*判断是否进行高级检索*/
$CF = 0; //标志是否进行高级检索
$TypeEP = array();
$UseEP = array();
$BrandEP = array();
$SSDEP = array();
$MemoryEP = array();
$CPUEP = array();
$ScreenEP = array();
$CardEP = array();
for ($k = 0; $k < sizeof($TypeChoose); $k++)
	if ($TypeChoose[$k] == TRUE) {
		$IsChosen[0] = true; //笔记本类型有要求
		$CF = 1;
		break;
	}
for ($k = 0; $k < sizeof($UseChoose); $k++)
	if ($UseChoose[$k] == TRUE) {
		$IsChosen[1] = true; //笔记本用途有要求
		$CF = 1;
		break;
	}
for ($k = 0; $k < sizeof($BrandChoose); $k++)
	if ($BrandChoose[$k] == TRUE) {
		$IsChosen[2] = true; //笔记本品牌有要求
		$CF = 1;
		break;
	}
for ($k = 0; $k < sizeof($MemoryChoose); $k++)
	if ($MemoryChoose[$k] == TRUE) {
		$IsChosen[3] = true; //笔记本内存容量有要求
		$CF = 1;
		break;
	}
for ($k = 0; $k < sizeof($SSDChoose); $k++)
	if ($SSDChoose[$k] == TRUE) {
		$IsChosen[4] = true; //笔记本硬盘容量有要求
		$CF = 1;
		break;
	}
for ($k = 0; $k < sizeof($CPUChoose); $k++)
	if ($CPUChoose[$k] == TRUE) {
		$IsChosen[5] = true; //笔记本处理器类型有要求
		$CF = 1;
		break;
	}
for ($k = 0; $k < sizeof($ScreenChoose); $k++)
	if ($ScreenChoose[$k] == TRUE) {
		$IsChosen[6] = true; //笔记本屏幕尺寸有要求
		$CF = 1;
		break;
	}
for ($k = 0; $k < sizeof($CardChoose); $k++)
	if ($CardChoose[$k] == TRUE) {
		$IsChosen[7] = true; //笔记本显卡类型有要求
		$CF = 1;
		break;
	}
if ($HighPrice != "" && $LowPrice != "")
	$CF = 1;

/*数据库查询*/
$Major_no = "SELECT * from Major where Mjr_name='$Major_name'";
$query_Major_no = mysqli_query($conn, $Major_no);
$row = mysqli_fetch_array($query_Major_no);
$EP_Hardware = "SELECT * from EP Join Hardware on EP.EPno=Hardware.EPno join One_Picture on EP.EPno=One_Picture.EPno";;
$Major_Software = "SELECT * from Major join Major_Software on Major.Mjr_no=Major_Software.Mjr_no join Software on Major_Software.Stype=Software.Stype where Major.Mjr_no =$row[0] and Software.System like 'Window%' union select * from Major join Major_Software on Major.Mjr_no=Major_Software.Mjr_no join Software on Major_Software.Stype=Software.Stype where Major.Mjr_no=$row[0] and Software.System like 'MacOS%'";
$Dislike = "SELECT * from Dislike where Uno='$User_name'";
$Interest_Software = "SELECT * from Interest join  Interest_Software on Interest.Ino=Interest_Software.Ino join Software ON Interest_Software.Sno=Software.Sno";
$query_EP_Hardware = mysqli_query($conn, $EP_Hardware); //查询所有电脑硬件信息+图片
$query_Major_Software = mysqli_query($conn, $Major_Software); //查询该专业-软件-硬件参数
$query_Dislike = mysqli_query($conn, $Dislike); //查询用户不喜欢列表
$query_Interest_Software = mysqli_query($conn, $Interest_Software); //查询用户用途列表
$EPInfo = array(); //电脑基本信息+电脑参数
$MajorRequest = array(); //专业所需软件对电脑的要求
$EP = array(); //满足要求的电脑
$EP2 = array();
$DReason = array(); //不喜欢的原因
$NEP = 0;

$Rnum = 0;
while ($row = mysqli_fetch_array($query_Major_Software)) {
	$MajorRequest[$i] = $row;
	$Rnum = $Rnum + 1;
}

$dnum = 0;
while ($row = mysqli_fetch_array($query_Dislike)) {
	$DReason[$dnum] = $row;
	$dnum = $dnum + 1;
}

$i = 0;
while ($row = mysqli_fetch_array($query_EP_Hardware)) {
	$EPInfo[$i] = $row;
	$i = $i + 1;
}

/*筛选满足专业需求的电脑*/
if (sizeof($MajorRequest) != 0) {
	SelectByRequest($EPInfo, $i, $MajorRequest, $Rnum, $EP, $NEP);
} else {
	$NEP = sizeof($EPInfo);
	for ($i = 0; $i < $NEP; $i++)
		$EP[$i] = $EPInfo[$i];
}
dislike($DReason, $dnum, $EP, $NEP, $LEP, $Lnum); // 筛选掉不感兴趣
PopularRanking($LEP, $Lnum); //按流行度进行排序

//$n = 0;
//if ($NEP > 50)
//	$n = 50;
//else
//	$n = $NEP;
//for ($i = 0; $i < $n; $i++)
//	$EP2[$i] = $EP[$i];

/*高级检索*/
if ($CF == 1) {
	$i = 0;
	$N = 0;
	$N1 = 0;
	$N2 = 0;
	$N3 = 0;
	$N4 = 0;
	$N5 = 0;
	$N6 = 0;
	$N7 = 0;
	$N8 = 0;
	$N9 = 0;
	$EP3 = array();
	$EP4 = array();
	if ($IsChosen[0]) { //检索笔记本类型
		if ($TypeChoose[0]) {
			for ($i = 0; $i < $NEP; $i++) {
				if (strstr($EP[$i]['EP_intro'], $TypeList[0])) {
					$TypeEP[$N1] = $EP[$i];
					$N1++;
				}
			}
		}
		if ($TypeChoose[1]) {
			for ($i = 0; $i < $NEP; $i++) {
				if (strstr($EP[$i]['EP_intro'], $TypeList[1])) {
					$TypeEP[$N1] = $EP[$i];
					$N1++;
				}
			}
		}
	} else {
		$TypeEP = $EP;
		$N1 = $NEP;
	}
	if ($IsChosen[1]) { //检索笔记本用途
		$UseEP = $TypeEP;
		$N2 = $N1;
	} else {
		$UseEP = $TypeEP;
		$N2 = $N1;
	}
	if ($IsChosen[2]) { //检索笔记本品牌
		for ($i = 0; $i < 8; $i++) {
			if ($BrandChoose[$i]) {
				for ($j = 0; $j < $N2; $j++) {
					if (strstr($UseEP[$j]['EP_intro'], $BrandList[$i])) {
						$BrandEP[$N3] = $UseEP[$j];
						$N3++;
					}
				}
			}
		}
	} else {
		$BrandEP = $UseEP;
		$N3 = $N2;
	}
	if ($IsChosen[3]) { //检索笔记本内存容量
		for ($i = 0; $i < 5; $i++) {
			if ($MemoryChoose[$i]) {
				for ($j = 0; $j < $N3; $j++) {
					if (strstr($BrandEP[$j]['Memery_capa'], substr($MemoryList[$i], 0, strlen($MemoryList[$i] - 1)))) {
						$MemoryEP[$N4] = $BrandEP[$j];
						$N4++;
					}
				}
			}
		}
	} else {
		$MemoryEP = $BrandEP;
		$N4 = $N3;
	}
	if ($IsChosen[4]) { //检索硬盘容量
		for ($i = 0; $i < 4; $i++) {
			if ($SSDChoose[$i]) {
				for ($j = 0; $j < $N4; $j++) {
					$MemoryEP[$j]['SSD'] = substr($MemoryEP[$j]['SSD'], 0, strlen($MemoryEP[$j]['SSD'] - 2));
					$SSDList[$i] = substr($SSDList[$i], 0, strlen($SSDList[$i] - 1));
					if (strstr($MemoryEP[$j]['SSD'], $SSDList[$i])) {
						$SSDEP[$N5] = $MemoryEP[$j];
						$N5++;
					}
				}
			}
		}
	} else {
		$SSDEP = $MemoryEP;
		$N5 = $N4;
	}
	if ($IsChosen[5]) { //检索处理器类型
		for ($i = 0; $i < 4; $i++) {
			if ($CPUChoose[$i]) {
				for ($j = 0; $j < $N5; $j++) {
					if (strstr($SSDEP[$j]['CPU_type'], $CPUList[$i])) {
						$CPUEP[$N5] = $SSDEP[$j];
						$N6++;
					}
				}
			}
		}
	} else {
		$CPUEP = $SSDEP;
		$N6 = $N5;
	}
	if ($IsChosen[6]) { //检索屏幕大小
		if ($ScreenChoose[0]) {
			for ($j = 0; $j < $N6; $j++) {
				if (floatval($CPUEP[$j]['Screen_size'] < 13.0)) {
					$ScreenEP[$N7] = $CPUEP[$j];
					$N7++;
				}
			}
		}
		if ($ScreenChoose[1]) {
			for ($j = 0; $j < $N6; $j++) {
				if (floatval($CPUEP[$j]['Screen_size'] > 13.0) && floatval($CPUEP[$j]['Screen_size'] < 13.9)) {
					$ScreenEP[$N7] = $CPUEP[$j];
					$N7++;
				}
			}
		}
		if ($ScreenChoose[2]) {
			for ($j = 0; $j < $N6; $j++) {
				if (floatval($CPUEP[$j]['Screen_size'] > 14.0) && floatval($CPUEP[$j]['Screen_size'] < 14.9)) {
					$ScreenEP[$N7] = $CPUEP[$j];
					$N7++;
				}
			}
		}
		if ($ScreenChoose[3]) {
			for ($j = 0; $j < $N6; $j++) {
				if (floatval($CPUEP[$j]['Screen_size'] > 15.0) && floatval($CPUEP[$j]['Screen_size'] < 15.9)) {
					$ScreenEP[$N7] = $CPUEP[$j];
					$N7++;
				}
			}
		}
		if ($ScreenChoose[4]) {
			for ($j = 0; $j < $N6; $j++) {
				if (floatval($CPUEP[$j]['Screen_size'] > 16.0)) {
					$ScreenEP[$N7] = $CPUEP[$j];
					$N7++;
				}
			}
		}
	} else {
		$ScreenEP = $CPUEP;
		$N7 = $N6;
	}
	if ($IsChosen[6]) { //检索显卡类型
		for ($i = 0; $i < 2; $i++) {
			if ($CardChoose[$i]) {
				for ($j = 0; $j < $N7; $j++) {
					if (strstr($ScreenEP[$j]['Card_type'], $CardList[$i])) {
						$CardEP[$N8] = $ScreenEP[$j];
						$N8++;
					}
				}
			}
		}
	} else {
		$CardEP = $ScreenEP;
		$N8 = $N7;
	}
	if ($HighPrice == 0 && $LowPrice == 0) {
		for ($j = 0; $j < $N8; $j++) {
			$EP3[$N9] = $CardEP[$j];
			$N9++;
		}
	} else if ($HighPrice == 0 && $LowPrice != 0) {
		for ($j = 0; $j < $N8; $j++) {
			if (floatval($CardEP[$j]['EP_price'] > floatval($LowPrice))) {
				$EP3[$N9] = $CardEP[$j];
				$N9++;
			}
		}
	} else if ($HighPrice != 0 && $LowPrice == 0) {
		for ($j = 0; $j < $N8; $j++) {
			if (floatval($CardEP[$j]['EP_price'] < floatval($HighPrice))) {
				$EP3[$N9] = $CardEP[$j];
				$N9++;
			}
		}
	} else {
		for ($j = 0; $j < $N8; $j++) {
			if (floatval($CardEP[$j]['EP_price'] > floatval($LowPrice)) && floatval($CardEP[$j]['EP_price'] < floatval($HighPrice))) {
				$EP3[$N9] = $CardEP[$j];
				$N9++;
			}
		}
	}
	PopularRanking($EP3, $N9); //按流行度进行排序
	if ($N9 < $page * 20) {
		for ($i = ($page - 1) * 20; $i < $N9; $i++) //翻页
			$EP4[$i] = $EP3[$i];
	} else {
		for ($i = ($page - 1) * 20; $i < $page * 20; $i++) //翻页
			$EP4[$i] = $EP3[$i];
	}
	echo json_encode($EP4, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} else {
	if ($Lnum < $page * 20) {
		for ($i = ($page - 1) * 20; $i < $Lnum; $i++) //翻页
			$EP2[$i] = $LEP[$i];
	} else {
		for ($i = ($page - 1) * 20; $i < $page * 20; $i++) //翻页
			$EP2[$i] = $LEP[$i];
	}
	echo json_encode($EP2, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
// 释放结果集+关闭MySQL数据库连接
mysqli_free_result($result);
mysqli_close($conn);
